/**
 * 返回歌曲时间的字符串显示
 * @param {integer} dt
 * @returns string
 */
export const formatDuration = dt => {
  if (!Number.isInteger(dt)) {
    return new TypeError('The duration must be a integer!')
  }
  // 228285 -> 229
  let sec = Math.ceil(dt / 1000)
  let minutes = Math.floor(sec / 60)
  sec = sec - minutes * 60

  minutes = minutes ? (minutes >= 10 ? String(minutes) : `0${minutes}`) : '00'
  sec = sec ? (sec >= 10 ? String(sec) : `0${sec}`) : '00'

  return `${minutes}:${sec}`
}

/**
 * 返回： 10月29日
 * @param {Date} time
 */
export const formatUpdateTime = time => {
  const date = new Date(time)
  return `${date.getMonth() + 1}月${date.getDate()}日`
}

/**
 * 返回 2020-10-30
 * @param {Date} time
 */
export const formatPublishTime = time => {
  const date = new Date(time)
  const month = date.getMonth() < 9 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
  const day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
  return `${date.getFullYear()}-${month}-${day}`
}

export default {}
